package com.xie.smfs.registry;

import com.xie.smfs.item.*;
import com.xie.smfs.item.SilentGhostEyeItem;
import com.xie.smfs.item.GhostMoneyItem;
import com.xie.smfs.block.GhostCoffinBlock;
import com.xie.smfs.registry.ModBlocks;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.item.*;
import net.minecraft.entity.EntityType;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.text.Text;
import net.minecraft.registry.Registry;

public class ModItems {
    // 物品注册工具方法
    private static Item registerItem(String name, Item item) {
        return Registry.register(Registries.ITEM, new Identifier("smfs", name), item);
    }

    // 红色鬼烛物品实例
    public static final Item RED_GHOST_CANDLE = registerItem("red_ghost_candle",
            new RedGhostCandleItem(new FabricItemSettings().maxCount(1).maxDamage(64)));

    // 白色鬼烛物品实例
    public static final Item WHITE_GHOST_CANDLE = registerItem("white_ghost_candle",
            new WhiteGhostCandleItem(new FabricItemSettings().maxCount(1).maxDamage(64)));

    // 锈迹斑斑的棺材钉注册
    public static final Item COFFIN_NAIL = registerItem("coffin_nail",
            new CoffinNailItem(new FabricItemSettings().maxCount(1)));

    // 锈迹斑斑的水果刀
    public static final Item RUSTY_FRUIT_KNIFE = registerItem("rusty_fruit_knife",
            new RustyFruitKnifeItem(new FabricItemSettings().maxCount(1).maxDamage(64)));

    // 鬼剪刀物品
    public static final Item GHOST_SCISSORS = registerItem("ghost_scissors",
            new GhostScissorsItem(new FabricItemSettings().maxCount(1).maxDamage(-1)));

    // 鬼钱物品

    // 3元鬼钱物品
    public static final Item GHOST_MONEY_3 = registerItem("ghost_money_3",
            new GhostMoneyItem(new FabricItemSettings().maxCount(64)));
    // 7元鬼钱物品
    public static final Item GHOST_MONEY_7 = registerItem("ghost_money_7",
            new GhostMoneyItem(new FabricItemSettings().maxCount(64)));

    // 照片物品
    public static final Item PHOTO = registerItem("photo",
            new PhotoItem(new FabricItemSettings().maxCount(1)));

    // 黄金容器物品
    public static final Item GOLDEN_CONTAINER = registerItem("golden_container",
            new GoldenContainerItem(new FabricItemSettings().maxCount(1)));

    // 鬼瓷物品
    public static final Item GHOST_PORCELAIN = registerItem("ghost_porcelain",
            new GhostPorcelainItem(new FabricItemSettings().maxCount(1)));

    // 沉寂的鬼眼物品
    public static final Item SILENT_GHOST_EYE = registerItem("silent_ghost_eye",
            new SilentGhostEyeItem(new FabricItemSettings().maxCount(1)));

    // 鬼糖果物品
    public static final Item GHOST_CANDY = registerItem("ghost_candy", new GhostCandyItem(new FabricItemSettings().maxCount(64)));

    // 鬼唱片物品
    public static final Item GHOST_RECORD = registerItem("ghost_record", new GhostRecordItem(new FabricItemSettings().maxCount(1)));
    public static final Item GHOST_COFFIN = registerItem("ghost_coffin", new BlockItem(ModBlocks.GHOST_COFFIN, new FabricItemSettings()));
    public static final Item RED_COFFIN = registerItem("red_coffin", new BlockItem(ModBlocks.RED_COFFIN, new FabricItemSettings()));
    public static final Item GOLD_COFFIN = registerItem("gold_coffin", new BlockItem(ModBlocks.GOLD_COFFIN, new FabricItemSettings()));
    public static final Item FOOD_GHOST_SPAWN_EGG = registerItem("food_ghost_spawn_egg", new SpawnEggItem(ModEntities.FOOD_GHOST, 0x0000FF, 0xFFFFFF, new FabricItemSettings()));

    // 添加敲门鬼刷怪蛋
    public static final Item QIAOMEN_GHOST_SPAWN_EGG = registerItem("qiaomen_ghost_spawn_egg",
            new SpawnEggItem(ModEntities.QIAOMEN_GHOST, 0x808080, 0xFFFFFF, new FabricItemSettings()));

    // 添加鬼刷怪蛋注册
    public static final Item TAITOU_GHOST_SPAWN_EGG = registerItem("taitou_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.TAITOU_GHOST, 0xFFA500, 0xFFFFFF, new FabricItemSettings()));

    // 添加低头鬼刷怪蛋
    public static final Item DITOU_GHOST_SPAWN_EGG = registerItem("ditou_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.DITOU_GHOST, 0x008000, 0xFFFFFF, new FabricItemSettings()));
        public static final Item GHOST_MERCHANT_SPAWN_EGG = registerItem("ghost_merchant_spawn_egg",
            new SpawnEggItem(ModEntities.GHOST_MERCHANT, 0x4A0080, 0xD3D3D3, new FabricItemSettings()));

    // 开箱鬼生成蛋
    public static final Item BOX_GHOST_SPAWN_EGG = registerItem("box_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.BOX_GHOST, 0x0000FF, 0xFFFFFF, new FabricItemSettings()));

    // 村民鬼生成蛋
    public static final Item VILLAGER_GHOST_SPAWN_EGG = registerItem("villager_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.VILLAGER_GHOST, 0x008000, 0xFFFFFF, new FabricItemSettings()));

        // 跳跃鬼生成蛋
    public static final Item JUMP_GHOST_SPAWN_EGG = registerItem("jump_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.JUMP_GHOST, 0x800080, 0xFFFFFF, new FabricItemSettings()));

    // 鬼雾生成蛋
    public static final Item FOG_GHOST_SPAWN_EGG = registerItem("fog_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.FOG_GHOST, 0xCCCCCC, 0xFFFFFF, new FabricItemSettings()));

    // 死亡凝视鬼刷怪蛋
    public static final Item DEATH_SIGHT_GHOST_SPAWN_EGG = registerItem("death_sight_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.DEATH_SIGHT_GHOST, 0x000000, 0xFF0000, new FabricItemSettings()));

    // 不可触摸鬼刷怪蛋
    public static final Item UNTOUCHABLE_GHOST_SPAWN_EGG = registerItem("untouchable_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.UNTOUCHABLE_GHOST, 0x999999, 0xFFFFFF, new FabricItemSettings()));

    // 方块鬼刷怪蛋
    public static final Item BLOCK_GHOST_SPAWN_EGG = registerItem("block_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.BLOCK_GHOST, 0x555555, 0xAAAAAA, new FabricItemSettings()));

    // 另一种鬼刷怪蛋
    public static final Item Lost_GHOST_SPAWN_EGG = registerItem("lost_ghost_spawn_egg",
        new SpawnEggItem(ModEntities.LOST_GHOST, 0x000000, 0x333333, new FabricItemSettings()));

    // 自定义物品组
    public static final ItemGroup GHOST_GROUP = FabricItemGroup.builder()
            .icon(() -> new ItemStack(RED_GHOST_CANDLE))
            .displayName(Text.translatable("itemGroup.smfs.ghost_items"))
            .entries((displayContext, entries) -> {
                entries.add(RED_GHOST_CANDLE);
                entries.add(WHITE_GHOST_CANDLE);
                entries.add(COFFIN_NAIL); // 添加棺材钉到物品组
                entries.add(GHOST_SCISSORS); // 添加鬼剪刀到物品组
                entries.add(RUSTY_FRUIT_KNIFE);
                entries.add(GHOST_CANDY);
                entries.add(GHOST_RECORD);
                entries.add(PHOTO);
                entries.add(GHOST_MONEY_3); // 添加3元鬼钱到物品组
                entries.add(GHOST_MONEY_7); // 添加7元鬼钱到物品组
                entries.add(GOLDEN_CONTAINER); // 添加黄金容器到物品组
                entries.add(GHOST_PORCELAIN); // 添加鬼瓷到物品组
                entries.add(SILENT_GHOST_EYE); // 添加沉寂的鬼眼到物品组
                entries.add(FOOD_GHOST_SPAWN_EGG);
                entries.add(QIAOMEN_GHOST_SPAWN_EGG);
                entries.add(TAITOU_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(DITOU_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(GHOST_MERCHANT_SPAWN_EGG.getDefaultStack());
                entries.add(BOX_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(VILLAGER_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(JUMP_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(FOG_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(DEATH_SIGHT_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(UNTOUCHABLE_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(BLOCK_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(Lost_GHOST_SPAWN_EGG.getDefaultStack());
                entries.add(GHOST_COFFIN);
                entries.add(RED_COFFIN);
                entries.add(GOLD_COFFIN);
            })
            .build();
    // 注册所有物品
    public static void registerItems() {
        Registry.register(Registries.ITEM_GROUP, new Identifier("smfs", "ghost_items"), GHOST_GROUP);
    }
}